package com.yz.design.strategyAndChain;

import java.util.List;

public class Client {

    public static void main(String[] args) {
        testChain();
    }

    /**
     * 策略模式+工厂+map
     *
     * @author: 广长
     * @date: 2020/11/11
     * @return: void
     */
    private static void testStrategy() {
        //模拟回执
        List<Receipt> receiptList = ReceiptBuilder.generateReceiptList();
        //策略上下文
        ReceiptStrategyContext receiptStrategyContext = new ReceiptStrategyContext();
        for (Receipt receipt : receiptList) {
            //获取并设置策略
            IReceiptHandleStrategy receiptHandleStrategy = ReceiptHandleStrategyFactory.getReceiptHandleStrategy(receipt.getType());
            receiptStrategyContext.setReceiptHandleStrategy(receiptHandleStrategy);
            //执行策略
            receiptStrategyContext.handleReceipt(receipt);
        }
    }

    /**
     * 责任链 + 反射
     *
     * @author: 广长
     * @date: 2020/11/11
     * @return: void
     */
    private static void testChain() {
        //模拟回执
        List<Receipt> receiptList = ReceiptBuilder.generateReceiptList();
        for (Receipt receipt : receiptList) {
            //回执处理链对象
            ReceiptHandleChain receiptHandleChain = new ReceiptHandleChain();
            receiptHandleChain.handleReceipt(receipt);
        }
    }
}